package fms.models;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;

import fms.classes.User;

public class UserDAO {
	
	private SqlSessionFactory sqlSessionFactory;

	public UserDAO(){
		
		try{
			sqlSessionFactory = MyBatisSqlConnection.getSqlSessionFactory();	
			
		}catch(Exception e){
			System.out.println("failed to get sqlSessionFactory");
		}
		
	}
	
	
	
	public void insertUser(User user){
		
		SqlSession session = sqlSessionFactory.openSession();
		
		try{
			
			session.insert("User.insertUser", user);
			session.commit();
		} finally{
			session.close();
		}
	}
	
	
	public User selectById(String userId){
		
		SqlSession session = sqlSessionFactory.openSession();
		try{
			User user = (User) session.selectOne("User.getByUserId", userId);
			return user;
				
		}	finally{
			session.close();
		}
	}
	
	
	
}
